package com.ming.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.domain.ProdComm;
import com.ming.service.ProdCommService;
import com.ming.vo.ProdCommOverview;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:何元才
 * @Desc:
 * @data:2021-04-01 21:13
 */
@RestController
@RequestMapping("prod/prodComm")
@Api(tags = "商品评论管理的接口")
public class ProdCommController {

    @Autowired
    private ProdCommService prodCommService;

    /**
     * 分页查询商品评论
     * @param page
     * @param prodComm
     * @return
     */
    @GetMapping("page")
    @ApiOperation("分页查询商品评论")
    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    public ResponseEntity<Page<ProdComm>> findProdCommPage(Page<ProdComm> page ,ProdComm prodComm){
        Page<ProdComm> prodCommPage = prodCommService.findProdCommPage(page,prodComm);
        return ResponseEntity.ok(prodCommPage);
    }




    // ------------- 前台接口  1.评论总览 好评率 总条数 每个级别有多少条
    @GetMapping("prodComm/prodCommData")
    @ApiOperation("根据商品id查询商品评论总览")
    public ResponseEntity<ProdCommOverview> getProdCommOverview(Long prodId){
        ProdCommOverview prodCommOverview = prodCommService.getProdCommOverview(prodId);
        return ResponseEntity.ok(prodCommOverview);
    }

    @GetMapping("prodComm/prodCommPageByProd")
    @ApiOperation("根据商品id分页查询商品评论")
    public ResponseEntity<Page<ProdComm>> getProdCommPage(Long prodId, Page<ProdComm> page, Integer evaluate){
        Page<ProdComm> prodCommPage = prodCommService.getProdCommPage(prodId , page , evaluate);
        return ResponseEntity.ok(prodCommPage);
    }


}
